package com.fs.sys.entityservice;

import com.fs.common.base.service.BaseService;
import com.fs.sys.bean.dto.UserDTO;
import com.fs.sys.bean.query.NoRoleUserQuery;
import com.fs.sys.bean.query.UserQuery;
import org.springframework.security.core.userdetails.UserDetailsService;

import java.util.List;
import java.util.Optional;

public interface UserEntityService extends BaseService<UserDTO, UserQuery>, UserDetailsService {
    Optional<UserDTO> findByUsername(String username);

    Optional<UserDTO> findByPhone(String phone);

    /**
     * 根据用户名、手机号判断用户是否存在
     */
    boolean userExists(String username, String phon);

    default Optional<UserDTO> findByWxOpenId(String openId) {
        return this.queryBuilder()
                .eq("wx_open_id", openId)
                .query()
                .stream().findAny();
    }

    /**
     * 查询无指定角色的用户
     * @param query 查询条件
     * @return 查询结果
     */
    List<UserDTO> queryUserNoRole(NoRoleUserQuery query);
}
